package org.Demo;

import java.util.Random;
import java.util.Scanner;

/*
* 模拟双色球
* */
public class Demo6 {
    public static void main(String[] args) {
        int[] userSelectNumber = userSelectNumber();
        printArray(userSelectNumber);
        int[] luckyNumbers = createLuckyNumbers();
        printArray(luckyNumbers);
        judge(userSelectNumber,luckyNumbers);
    }

    public static void printArray(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(i == arr.length - 1 ? arr[i] : arr[i] + ",");
        }
        System.out.println("]");
    }

    //    用户投注号码（前6个红球，最后1个蓝球）
    public static int[] userSelectNumber() {
        Scanner scanner = new Scanner(System.in);
        int[] userSelectNumber = new int[7];
//        六个红球
        for (int i = 0; i < userSelectNumber.length - 1; i++) {
            while (true) {
                System.out.println("请您输入第" + (i + 1) + "个红球号码（1-33之间，不能重复）");
                int number = scanner.nextInt();
                if (number < 1 || number > 33) {
                    System.out.println("您输入的号码不在1-33之间，请确认");
                } else {
                    if (exist(userSelectNumber, number)) {
                        System.out.println("您当前选择的号码重复，请重新选择");
                    } else {
                        userSelectNumber[i] = number;
                        break;
                    }
                }
            }
        }
//        篮球
        while (true) {
            System.out.println("请您输入蓝球号码：");
            int number = scanner.nextInt();
            if (number < 1 || number > 16) {
                System.out.println("对不起您输入的号码范围不对");
            } else {
                userSelectNumber[6] = number;
                break;
            }
        }
        return userSelectNumber;
    }

    private static boolean exist(int[] userSelectNumber, int number) {
        for (int i = 0; i < userSelectNumber.length; i++) {
            if (userSelectNumber[i] == number) {
                return true;
            }
        }
        return false;
    }

    public static int[] createLuckyNumbers() {
        int[] numbers = new int[7];

        Random r = new Random();
        for (int i = 0; i < numbers.length - 1; i++) {
            while (true) {
                int number = r.nextInt(33) + 1;
                if (!exist(numbers, number)) {
                    numbers[i] = number;
                    break;
                }
            }
        }
        numbers[6] = r.nextInt(16) + 1;
        return numbers;
    }

    public static void judge(int[] userNumber,int[] luckyNumber){
        int redCount = 0;
        int blueCount = 0;

//        判断红球号码
        for (int i = 0; i < userNumber.length-1; i++) {
            for (int j = 0; j < luckyNumber.length-1; j++) {
                if(userNumber[i] == luckyNumber[j]){
                    redCount++;
                    break;
                }
            }
        }
//        判断蓝球号码
        blueCount = userNumber[6] == luckyNumber[6]?1:0;
        System.out.println("您命中的红球数量是："+redCount);
        System.out.println("您命中的蓝球数量是："+blueCount);

        if(redCount ==6 && blueCount==1){
            System.out.println("恭喜您中奖1000万，可以享受人生了");
        }else if(redCount == 6 && blueCount ==0){
            System.out.println("恭喜您中奖500万");
        }
        else if(redCount == 5 && blueCount ==1){
            System.out.println("恭喜您中奖3000元");
        }
        else if(redCount == 5 && blueCount ==0 || redCount == 4 && blueCount ==1){
            System.out.println("恭喜您中奖200元");
        }
        else if(redCount == 4 && blueCount ==0 || redCount == 3 && blueCount ==1){
            System.out.println("恭喜您中奖100元");
        }
        else if(redCount == 4 && blueCount ==0 || redCount == 3 && blueCount ==1){
            System.out.println("恭喜您中奖10元");
        }
        else if(redCount == 2 && blueCount ==1 || redCount == 1 && blueCount ==1|| redCount == 0 && blueCount ==1){
            System.out.println("恭喜您中奖5元");
        }
        else{
            System.out.println("很抱歉，您没有中奖");
        }

    }
}

